<!doctype>
<html>
	<head>
		
	</head>
	<body>

<script>

function runAsync(){
	var p = new Promise(function(resolve, reject){
        //做一些异步操作
        setTimeout(function(){
            console.log('执行完成');
            resolve('随便什么数据','2222');
        }, 2000);
    });
    return p;       
}


function runAsync1(){
    var p = new Promise(function(resolve, reject){
        //做一些异步操作
        setTimeout(function(){
            console.log('异步任务1执行完成');
            resolve('随便什么数据1');
        }, 1000);
    });
    return p;            
}
function runAsync2(){
    var p = new Promise(function(resolve, reject){
        //做一些异步操作
        setTimeout(function(){
            console.log('异步任务2执行完成');
            resolve('随便什么数据2');
        }, 2000);
    });
    return p;            
}
function runAsync3(){
    var p = new Promise(function(resolve, reject){
        //做一些异步操作
        setTimeout(function(){
            console.log('异步任务3执行完成');
			reject("抛出个异常");
            //resolve('随便什么数据3');
        }, 2000);
    });
    return p;            
}
function runAsync4(){
    var p = new Promise(function(resolve, reject){
        //做一些异步操作
        setTimeout(function(){
            console.log('异步任务4执行完成');
            resolve('随便什么数据4');
        }, 2000);
    });
    return p;            
}

runAsync1().then(
	function(data){
		console.log(data);
		return runAsync2();
	}
).then(
	function(data){
		console.log(data);
		return runAsync3();
	}
).then(
	function(data){
		console.log(data);
		return runAsync4();
	}
).then(function(data){
    console.log(data);
}).catch(function(reason){
    console.log('rejected');
    console.log(reason);
});;

</script>			

	</body>
</html>